Skip to content

Conversation

@saifsultanc
Copy link
Contributor

Context

⛑️ Ticket(s): https://secure.helpscout.net/conversation/3028599571/87494

Summary

When using the gpppw_word_count snippet to populate a text field with the word count from a paragraph field, we relied on triggering the .change() event to ensure that the value could be used in Gravity Forms conditional logic. However, this approach caused a JavaScript error — specifically Uncaught RangeError: Maximum call stack size exceeded — which ultimately prevented the form from loading in the browser.

The root cause was that .change() was being triggered even when the field value hadn’t changed. Since that field was used in conditional logic, Gravity Forms repeatedly re-evaluated conditions and retriggered the same logic, leading to an infinite loop.

This PR proposes to add a check to compare the existing value of the field #input_GFFORMID_2 with the new wordCount. The .change() event is now only triggered when the new value differs from the current one, preventing unnecessary logic execution and recursive event loops.

By avoiding redundant .change() triggers, we prevent conditional logic from being re-applied unnecessarily. This breaks the recursive chain and ensures the form loads and functions correctly without JavaScript errors.

BEFORE (Samuel):
https://www.loom.com/share/5d47f02f47b24e39a619fe4e6959ffab

AFTER:
https://www.loom.com/share/ffee4fdb11694477a633fa424a0e1ec0

…not working with Conditional Logic in play.

`gpppw-capture-count-as-field-value.js`: Fixed an issue with snippet not working with Conditional Logic in play.
@coderabbitai
Copy link

coderabbitai bot commented Aug 7, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The code was updated to change the target field ID from "4" to "2" for setting a word count value. The update now checks if the field's value differs before setting it, updates the value if needed, triggers a change event, and returns the word count.

Changes

Cohort / File(s) Change Summary
Word Count Field Update Logic
gp-pay-per-word/gpppw-capture-count-as-field-value.js
Changed target field ID from "4" to "2", only updates value if changed, triggers change event, and returns word count.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Suggested reviewers

  • veryspry

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7490db2 and 0522c2e.

📒 Files selected for processing (1)
  • gp-pay-per-word/gpppw-capture-count-as-field-value.js (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch saif/fix/87494-fix-gppw-count-cl

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

github-actions bot commented Aug 7, 2025

Warnings
⚠️ When ready, don't forget to request reviews on this pull request from your fellow wizards.

Generated by 🚫 dangerJS against 7490db2

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
gp-pay-per-word/gpppw-capture-count-as-field-value.js (1)

15-18: Excellent fix for the infinite loop issue - consider using strict equality.

This conditional check perfectly addresses the "Maximum call stack size exceeded" error by preventing redundant .change() events. The logic correctly breaks the recursive loop that was occurring when Gravity Forms conditional logic repeatedly re-evaluated.

Consider using strict equality (!==) for more robust comparison:

-	if ( $field.val() != wordCount ) {
+	if ( $field.val() !== wordCount ) {

This ensures type-safe comparison since form field values are strings while wordCount might be a number.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8eef25a and 7490db2.

📒 Files selected for processing (1)
  • gp-pay-per-word/gpppw-capture-count-as-field-value.js (1 hunks)
🔇 Additional comments (2)
gp-pay-per-word/gpppw-capture-count-as-field-value.js (2)

12-13: LGTM - Field ID configuration updated correctly.

The field ID change from "4" to "2" and the corresponding comment update are correct and align with the specific use case requirements.


20-20: Good practice - explicit return statement improves clarity.

Adding the explicit return wordCount; statement is excellent for filter functions. This ensures the filter chain works correctly and makes the function's intent explicit.

…not working with Conditional Logic in play.
@saifsultanc saifsultanc merged commit d6e5edf into master Aug 8, 2025
0 of 3 checks passed
@saifsultanc saifsultanc deleted the saif/fix/87494-fix-gppw-count-cl branch August 8, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants